﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.Utils;
using System.Collections.Generic;
using Ccit.OA.UserControls;
using Ccit.Mgoa.MsPsnset;

namespace Ccit.Mgoa.Collaboration
{
    public class CollaborateBLL
    {
        private ICollaborate oCollaborate;

        /// <summary>
        /// 根据条件获得协作类型
        /// </summary>
        /// <param name="msQuery"></param>
        /// <returns></returns>
        public List<MsCollaborativeType> GetCollaborativeType(MsQuery msQuery)
        {
            CreateObject();
            List<MsCollaborativeType> lstCollaborativeType = oCollaborate.GetCollaborativeType(msQuery);
            Dispose();
            return lstCollaborativeType;
        }

        /// <summary>
        /// 删除协作类型
        /// </summary>
        /// <param name="sTypeIds"></param>
        /// <returns></returns>
        public bool DeleteCollaborativeType(string sTypeIds)
        {
            CreateObject();
            bool bFlag = oCollaborate.DeleteCollaborativeType(sTypeIds);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 根据Id获得协作类型信息
        /// </summary>
        /// <param name="sTypeId"></param>
        /// <returns></returns>
        public MsCollaborativeType GetCollaborativeTypeById(string sTypeId)
        {
            CreateObject();
            MsCollaborativeType msCollaborativeType = oCollaborate.GetCollaborativeTypeById(sTypeId);
            Dispose();
            return msCollaborativeType;
        }

        /// <summary>
        /// 保存协作类型信息
        /// </summary>
        /// <param name="msCollaboration"></param>
        /// <returns></returns>
        public string SaveCollaboration(MsCollaborativeType msCollaboration)
        {
            CreateObject();
            string sResult = oCollaborate.SaveCollaboration(msCollaboration);
            Dispose();
            return sResult;
        }

        /// <summary>
        /// 根据条件获得协作信息
        /// </summary>
        /// <param name="msQuery"></param>
        /// <returns></returns>
        public List<MsCollaborativeTopic> GetCollaborativeTopicListByQuery(MsQuery msQuery)
        {
            CreateObject();
            List<MsCollaborativeTopic> lstCollaborativeTopic = oCollaborate.GetCollaborativeTopicListByQuery(msQuery);
            Dispose();
            return lstCollaborativeTopic;
        }

        /// <summary>
        /// 获得当前用户权限范围内的协作类型
        /// </summary>
        /// <param name="sPowerType">权限类型 1：管理权限 2：发布权限</param>
        /// <returns></returns>
        public List<MsCollaborativeType> GetPowerRangeCollaborativeType(string sPowerType)
        {
            CreateObject();
            List<MsCollaborativeType> lstCollaborativeType = oCollaborate.GetPowerRangeCollaborativeType(sPowerType);
            Dispose();
            return lstCollaborativeType;
        }

        /// <summary>
        /// 更改协作状态
        /// </summary>
        /// <param name="sId">协作ID</param>
        /// <param name="sFinishDate">终止日期</param>
        /// <param name="bKeepCommInfo">是否保留交流信息</param>
        /// <param name="sFinishType">start：发布协作 restart：重启协作 stop：终止协作（手动）0：终止协作（日期过期自然终止）</param>
        /// <returns></returns>
        public bool ChangeCollaborativeStatus(string sId, string sFinishDate, bool bKeepCommInfo, string sOperType)
        {
            CreateObject();
            bool bFlag = oCollaborate.ChangeCollaborativeStatus(sId, sFinishDate, bKeepCommInfo, sOperType);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 保存协作信息
        /// </summary>
        /// <param name="msCollaborativeTopic"></param>
        /// <returns></returns>
        public string SaveCollaborativeTopic(MsCollaborativeTopic msCollaborativeTopic)
        {
            CreateObject();
            string sResult = oCollaborate.SaveCollaborativeTopic(msCollaborativeTopic);
            Dispose();
            return sResult;
        }

        /// <summary>
        /// 根据ID获得协作信息
        /// </summary>
        /// <param name="sId"></param>
        /// <returns></returns>
        public MsCollaborativeTopic GetCollaborativeTopicById(string sId)
        {
            CreateObject();
            MsCollaborativeTopic message = oCollaborate.GetCollaborativeTopicById(sId);
            Dispose();
            return message;
        }

        /// <summary>
        /// 根据协作ID获得其回复信息
        /// </summary>
        /// <param name="sCollaborativeId"></param>
        /// <returns></returns>
        public List<MsComment> GetCollaborativeComment(string sCollaborativeId)
        {
            CreateObject();
            List<MsComment> lstComment = oCollaborate.GetCollaborativeComment(sCollaborativeId);
            Dispose();
            return lstComment;
        }

        /// <summary>
        /// 删除协作信息
        /// </summary>
        /// <param name="sIds"></param>
        /// <returns></returns>
        public bool DeleteCollaboration(string sIds)
        {
            CreateObject();
            bool bFlag = oCollaborate.DeleteCollaboration(sIds);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 发表回复
        /// </summary>
        /// <param name="msComment"></param>
        /// <returns></returns>
        public string SaveComment(MsComment msComment)
        {
            CreateObject();
            string sResult = oCollaborate.SaveComment(msComment);
            Dispose();
            return sResult;
        }

        /// <summary>
        /// 根据ID获得评论详细信息
        /// </summary>
        /// <param name="sCommentId"></param>
        /// <returns></returns>
        public MsComment GetCommentById(string sCommentId)
        {
            CreateObject();
            MsComment msComment = oCollaborate.GetCommentById(sCommentId);
            Dispose();
            return msComment;
        }

        /// <summary>
        /// 根据类别编号获得提醒设置
        /// </summary>
        /// <param name="sTypeCode">协作提醒：a4</param>
        /// <returns></returns>
        public MsRemind GetRemindSetByTypeCode(string sTypeCode)
        {
            CreateObject();
            MsRemind msReind = oCollaborate.GetRemindSetByTypeCode(sTypeCode);
            Dispose();
            return msReind;
        }

        /// <summary>
        /// 创建数据层对象
        /// </summary>
        private void CreateObject()
        {
            if (oCollaborate == null)
                oCollaborate = (ICollaborate)Factory.CreateObject("Ccit.Mgoa.Collaboration.dll", "Ccit.Mgoa.Collaboration.Collaborate", ImportComponentType.DotNetDll, null);
        }

        /// <summary>
        /// 释放数据层对象
        /// </summary>
        private void Dispose()
        {
            if (oCollaborate != null)
                oCollaborate = null;
        }
    }
}
